﻿using System;
using System.Web;

namespace VK.Comm.Session
{
    public static class SessionOperate<T> where T : class
    {
        public static void SetEntity(string sessionKey, T Entity)
        {
            HttpContext.Current.Session.Contents[sessionKey] = Entity;
        }

        public static T GetEntity(string sessionKey)
        {
            T Entity = HttpContext.Current.Session.Contents[sessionKey] as T;
            return Entity;
        }

        public static T GetEntity(string sessionKey, bool isRemove)
        {
            T Entity = HttpContext.Current.Session.Contents[sessionKey] as T;
            if (isRemove)
            {
                RemoveEntity(sessionKey);
            }
            return Entity;
        }

        public static void RemoveEntity(string sessionKey)
        {
            HttpContext.Current.Session.Remove(sessionKey);
        }

        public static bool IsExist(string sessionKey)
        {
            return HttpContext.Current.Session.Contents[sessionKey] != null;
        }
    }
}
